package com.mars.component.scheduler.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mars.common.spring.SpringContextHolder;
import com.mars.component.scheduler.entity.SchedulerTask;
import com.mars.component.scheduler.service.SchedulerHandler;
import com.mars.component.scheduler.service.SchedulerTaskService;
import com.mars.component.scheduler.utlis.SchedulerUtils;

@Service
public class SchedulerHanlderImpl implements SchedulerHandler {

	@Autowired
	private SchedulerTaskService schedulerTaskService ;
	
	@Autowired
	private SchedulerUtils schedulerUtils ;

	@Override
	public void createScheduleJob(SchedulerTask task) {
		
		this.schedulerTaskService.insertSelective(task) ;
		
		this.schedulerUtils.createScheduleJob(task);
		
		
	}

	@Override
	public void createScheduleJob4Spring(SchedulerTask task) {
		if(task.getBeanName() != null) {
			SpringContextHolder.getBean(task.getBeanName()) ;
 		}
		this.schedulerTaskService.insertSelective(task) ;
		
		this.schedulerUtils.createScheduleJob4Spring(task);
	}
	
	
}
